﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Mogre;

namespace ProjetSMA.View.Mogre
{
    class Food3D : Element3D
    {

        private Root m_root;
        private bool m_flag ;
        private float m_width = 0.06f;
        private float m_compt = 0f;
        private float m_compt_name = 0f;
        private Vector3 m_vector_scale = new Vector3(0, 0, 0);
        private ParticleSystem m_system;
        private int m_time = 200;
        private bool m_eaten = false;

        private System.Timers.Timer m_timer;

        public Food3D(Model.Element par_item, SceneManager par_smngr, string par_name, Root par_root)
            : base(par_item, par_smngr, par_name)
        {
            m_root = par_root;
            m_flag = true;
            m_timer = new System.Timers.Timer(500);  
        }

        public override void Initialisation()
        {
            m_entity = m_scene_mngr.CreateEntity(m_name, "cube.mesh");

            m_node = m_scene_mngr.RootSceneNode.CreateChildSceneNode(m_name);
            m_node.Position = new Vector3(m_position.x, m_position.y + m_coef * m_height_item + 14, m_position.z);
            m_node.Scale(0.03f, 0.03f, 0.03f);

            m_entity.SetMaterialName("Examples/ElementField3DQuint");
            m_entity.Visible = true;
            m_entity.CastShadows = false;

            m_node.AttachObject(m_entity);

            m_system = m_scene_mngr.CreateParticleSystem(m_name+"_particle", "Space/Food");
            m_system.Emitting = true;
            m_node.AttachObject(m_system);
            
            m_timer.Elapsed += new ElapsedEventHandler(timer_Tick_food);
            m_timer.Interval = (m_time) * (1);
            m_timer.Enabled = true;
            m_timer.Start();

        }

        public void timer_Tick_food(object sender, EventArgs e)
        {
            try
            {

                if (m_item.Food != null)
                {
                    m_entity.Visible = true;
                    m_system.Emitting = true;
                }
                else
                {
                    m_entity.Visible = false;
                    m_system.Emitting = false;
                    m_timer.Stop();
                }
            }
            catch (Exception de)
            {

            }
        }




        public void DisplayEating()
        {

        }

        void DestroyDisplay()
        {

        }

    }
}
